<%--
  Created by IntelliJ IDEA.
  User: 陌·笙
  Date: 2019-01-08
  Time: 20:40
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>入库审核</title>
    <jsp:include page="/comm/tag.jsp"/>
    <script>
        $(function(){
            $("#zstable").bootstrapTable({
                url:"/godowns/showGoDetails",
                height:800,
                pageSize:20,
                pageNumber:1,
                pageList:[10,20],
                contenteditable:true,
                //启用分页，但是默认情况下，是客户端分页的
                pagination:true,
                sidePagination:'server',
                queryParams:function(params){
                    var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                        limit: params.limit,  //页面大小
                        offset: params.offset, //页码
                        seat:$("[name='seat']").val(),
                    };
                    return temp;
                },
                locale:'zh-CN',//中文支持,
                toolbar:'#top',
                columns:[
                    {field:"seat",title:"单号",align:"center"},
                    {field:"shop.shopName",title:"商品名称",align:"center"},
                    {field:"shop.shopType",title:"手机型号",align:"center"},
                    {field:"shop.shopprice",title:"进价",align:"center"},
                    {field:"shop.shopcolor",title:"商品颜色",align:"center"},
                    {field:"gdNum",title:"应到数量",align:"center"},
                    {field:"gdNums",
                        title:"实到数量",
                        align:"center",
                        editable: {
                            type: 'text',
                            title: '实到数量',
                            validate: function (v) {
                                if (!v) return '实到数量不能为空';

                            }
                        }
                    },
                    {field:"gdtotal",title:"应付金额",align:"center"},
                    {field:"gdtotals",title:"实付金额",align:"center"},
                    {field:"firm.firmName",title:"生产厂商",align:"center"},
                    {
                        title:"备注",
                        align:"center",
                        formatter:function(value,row,index){
                            return " <button class=\"btn btn-danger\" onclick=\"up('"+index+"')\" > <span class=\"glyphicon glyphicon-plus\"></span>&nbsp;&nbsp;修改备注</button>&nbsp;&nbsp;&nbsp;"
                        }
                    },
                ],
                onEditableSave: function (field, row, oldValue, $el) {
                    $.ajax({
                        type: "post",
                        url: "/godowns/upGoGdNums",
                        data: {"gdId":row.gdId,"gdNums":row.gdNums,"price":row.shop.shopprice,"seat":row.seat},
                        dataType: 'JSON',
                        success: function (data, status) {
                            if (status == "success") {
                                $("#zstable").bootstrapTable("load",data);
                                $.ajax({
                                    type:"post",
                                    url:"/godowns/total",
                                    data:{"seat":row.seat},
                                    success:function (data) {
                                        $("[name='price']").val(data.total);
                                        $("[name='nums']").val(data.num);
                                        $("#myModal").modal('hide');
                                    }
                                })
                                alert('修改数据成功');
                            }
                        },
                        error: function () {
                            alert('编辑失败');
                        },
                        complete: function () {

                        }

                    });
                }
            });
        })
        function kk() {
            $("#zstable").bootstrapTable({
                url:"/godowns/showGoDetails",
                height:800,
                pageSize:20,
                pageNumber:1,
                pageList:[10,20],
                contenteditable:true,
                //启用分页，但是默认情况下，是客户端分页的
                pagination:true,
                sidePagination:'server',
                queryParams:function(params){
                    var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                        limit: params.limit,  //页面大小
                        offset: params.offset, //页码
                        seat:null,
                    };
                    return temp;
                },
                locale:'zh-CN',//中文支持,
                toolbar:'#top',
                columns:[
                    {field:"seat",title:"单号",align:"center"},
                    {field:"shop.shopName",title:"商品名称",align:"center"},
                    {field:"shop.shopType",title:"手机型号",align:"center"},
                    {field:"shop.shopprice",title:"进价",align:"center"},
                    {field:"shop.shopcolor",title:"商品颜色",align:"center"},
                    {field:"gdNum",title:"应到数量",align:"center"},
                    {field:"gdNums",
                        title:"实到数量",
                        align:"center",
                        editable: {
                            type: 'text',
                            title: '实到数量',
                            validate: function (v) {
                                if (!v) return '实到数量不能为空';

                            }
                        }
                    },
                    {field:"gdtotal",title:"应付金额",align:"center"},
                    {field:"gdtotals",title:"实付金额",align:"center"},
                    {field:"firm.firmName",title:"生产厂商",align:"center"},
                    {
                        title:"备注",
                        align:"center",
                        formatter:function(value,row,index){
                            return " <button class=\"btn btn-danger\" onclick=\"up('"+index+"')\" > <span class=\"glyphicon glyphicon-plus\"></span>&nbsp;&nbsp;修改备注</button>&nbsp;&nbsp;&nbsp;"
                        }
                    },
                ],
                onEditableSave: function (field, row, oldValue, $el) {
                    $.ajax({
                        type: "post",
                        url: "/godowns/upGoGdNums",
                        data: {"gdId":row.gdId,"gdNums":row.gdNums,"price":row.shop.shopprice,"seat":row.seat},
                        dataType: 'JSON',
                        success: function (data, status) {
                            if (status == "success") {
                                $("#zstable").bootstrapTable("load",data);
                                $.ajax({
                                    type:"post",
                                    url:"/godowns/total",
                                    data:{"seat":row.seat},
                                    success:function (data) {
                                        $("[name='price']").val(data.total);
                                        $("[name='nums']").val(data.num);
                                        $("#myModal").modal('hide');
                                    }
                                })
                                alert('修改数据成功');
                            }
                        },
                        error: function () {
                            alert('编辑失败');
                        },
                        complete: function () {

                        }

                    });
                }
            });
        }
    </script>
    <script>
        function show(index){
            $("#mytable").bootstrapTable("check",index);//根据索引让该行选中
            var a=$("#mytable").bootstrapTable("getSelections")[0];
            $("[name='seat']").val(a.seat);
            $(".totals").html(a.audit.presetPrice);
            $(".nums").html(a.audit.sums);
            $("[name='price']").val(a.audit.price);
            $("[name='nums']").val(a.audit.sums);
            var seat=$("[name='seat']").val();
            $.ajax({
                type:"post",
                url:"/godowns/showGoDetails",
                data:{"seat":seat,"offset":0,"limit":20},
                success:function(data){
                    $("#zstable").bootstrapTable("load",data);
                    $("#mytable").bootstrapTable("uncheck",index);//取消选中
                    $.ajax({
                        type:"post",
                        url:"/godowns/total",
                        data:{"seat":seat},
                        success:function (data) {
                            $("[name='price']").val(data.total);
                            $("[name='nums']").val(data.num);
                        }
                    })
                    $("#modal-id").modal('hide');
                }
            })
        }
        function submits(){
            var seat=$("[name='seat']").val();
            var remark=$("[name='beizhu']").val();
            if(seat==""){
                swal("错误", "请选择要审核的单号", "error");
            }else{
                $.ajax({
                    type:"post",
                    url:"/godowns/flag",
                    data:{"seat":seat},
                    success:function(data){
                        if(data){
                            swal({
                                title: "本次进价和上次进价不同!",
                                text: "审核将更改上次进价，请谨慎操作",
                                type: "warning",
                                showCancelButton: true,
                                confirmButtonColor: "#DD6B55",
                                confirmButtonText: "审核",
                                closeOnConfirm: false
                            }, function () {
                                $.ajax({
                                    type: "post",
                                    url: "/godowns/shenhe",
                                    data: {"seat": seat,"remark":remark},
                                    success: function (datas){
                                        $('#zstable').bootstrapTable('destroy');
                                        kk();
                                        $('#mytable').bootstrapTable('destroy');
                                        sk();
                                        $(".totals").html("0.00");
                                        $(".nums").html(0);
                                        $("[name='price']").val("0.00");
                                        $("[name='nums']").val("0");
                                        $("beizhu").val("");
                                        swal("审核成功！", "您已经审核了这条单号", "success");
                                    }
                                })
                            })
                        }else{
                            $.ajax({
                                type: "post",
                                url: "/godowns/shenhe",
                                data: {"seat": seat,"remark":remark},
                                success: function (datas){
                                    console.log(datas);
                                    $('#zstable').bootstrapTable('destroy');
                                    $('#mytable').bootstrapTable('destroy');
                                    sk();
                                    kk();
                                    $(".totals").html("0.00");
                                    $(".nums").html(0);
                                    $("[name='price']").val("0.00");
                                    $("[name='nums']").val("0");
                                    $("beizhu").val("");
                                    swal("审核成功！", "您已经审核了这条单号", "success");
                                }
                            })
                        }
                    }
                })
            }
        }
    </script>
</head>
<body>
<div style="margin-left: 50px;margin-right: 50px">
    <input type="hidden" name="seat">
    <div class="#top" style="margin-top: 50px">
        <div class="col-md-12">
            <form action="" method="post" role="form" id="okform" class="form-horizontal">
                <div class="form-group col-md-1">
                    <a class="btn btn-primary" data-toggle="modal" href="#modal-id"><span class="glyphicon glyphicon-plus"></span>&nbsp;&nbsp;添加审核</a>
                </div>
                <div class="form-group col-md-3">
                    <label for="" style="color: red;font-size: 20px" class="col-lg-7">应付金额:<span style="color: red;font-size: 20px" class="totals">0.00</span></label>
                    <label for="" style="color: blue;font-size: 20px" class="col-lg-5">应到数量:<span class="nums" style="color: blue;font-size: 20px">0</span></label>
                </div>
                <div class="form-group col-md-8">
                    <label for="" style="color: red;font-size: 20px; text-align: right" class="col-lg-2">实付金额:</label>
                    <div class=" col-lg-2">
                        <input type="text" name="price" disabled class="form-control" placeholder="0.00">
                    </div>
                    <label for="" style="color: red;font-size: 20px; text-align: right" class="col-lg-2">实到数量:</label>
                    <div class=" col-lg-2">
                        <input type="text" name="nums" disabled class="form-control" placeholder="0" >
                    </div>
                    <label for="" style="color: red;font-size: 20px; text-align: right" class="col-lg-1">备注:</label>
                    <div class=" col-lg-3">
                        <input type="text" name="beizhu" class="form-control" placeholder="" >
                    </div>
                </div>
                <button type="button" class="btn btn-primary btn-info glyphicon glyphicon-save-file" onclick="submits()">保存</button>
            </form>
        </div><%--搜索框--%>
    </div><%--搜索框--%>
    <table id="zstable"></table>
    <div class="modal fade" id="modal-id">
        <div class="modal-dialog" style="width: 1200px">
            <div class="modal-content" style="width: 1200px">
                <div class="modal-body" style="width: 1200px">
                    <div class="#top" style="margin-top: 10px">
                        <div class="col-md-12">
                            <form action="" method="post" role="form" class="form-horizontal">
                                <div class="col-md-1 pull-right">
                                    <button type="button" class="btn btn-primary btn-info glyphicon glyphicon-search" onclick="cha()">查询</button>
                                </div>
                                    <div class="form-group col-md-4 pull-right">
                                        <label for="" class="col-md-4 control-label">单号查询:</label>
                                        <div class="col-md-8">
                                            <input type="text" class="form-control" name="seats" placeholder="可模糊查询">
                                        </div>
                                    </div>
                            </form>
                        </div><%--搜索框--%>
                        <table id="mytable" class="table-striped"></table>
                    </div>

                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
    <div class="modal inmodal" id="myModal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static" data-keyboard="false">
        <div class="modal-dialog">
            <div class="modal-content animated bounceInRight">
                <div class="modal-header">
                    </button>
                    <i class="fa fa-laptop modal-icon"></i>
                    <h4 class="modal-title">录入信息</h4>
                    <small class="font-bold">入库商品录入信息</small>
                </div>
                <div class="modal-body">
                    <form action="" method="post" role="form" id="myform" class="form-horizontal">
                        <div class="form-group" style="font-size: 15px">
                            <div class="col-md-4">
                                <label for="">商品名称:</label>
                                <label for="" id="shopName">oppoK1</label>
                            </div>
                            <div class="col-md-4">
                                <label for="">商品型号:</label>
                                <label for="" id="shopType">4G+128</label>
                            </div>
                            <div class="col-md-4">
                                <label for="">商品颜色:</label>
                                <label for="" id="shopcolor">黑色</label>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-2" style="text-align: center">备注信息:</label>
                            <div class="col-md-10">
                                <textarea class="form-control" id="beizhu" rows="3" name="beizhu"></textarea>
                                <input type="hidden" name="gdId" class="form-control">
                                <input type="hidden" name="tableId" class="form-control">
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-white closes">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="smt()">保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    function smt(){
        var gdId=$("[name='gdId']").val();
        var seat=$("[name='seat']").val();
        var beizhu=$("#beizhu").val();
        var opts = $("#zstable").bootstrapTable("getOptions");
        limit = opts.pageSize ;
        offset = (opts.pageNumber-1) * limit;
        $.ajax({
            type:"post",
            url:"/godowns/upbeizhu",
            data:{"gdId":gdId,"limit":limit,"offset":offset,"seat":seat,"beizhu":beizhu},
            success:function (data) {
                $("#zstable").bootstrapTable("load",data);
                $("#myModal").modal('hide');
            }
        })
    }
    function up(index){
        $("#zstable").bootstrapTable("check",index);//根据索引让该行选中
        var a=$("#zstable").bootstrapTable("getSelections")[0];
        $("#beizhu").val(a.beizhu);
        $("[name='tableId']").val(index);
        $("[name='gdId']").val(a.gdId);
        $("#shopName").html(a.shop.shopName);
        $("#shopType").html(a.shop.shopType);
        $("#shopcolor").html(a.shop.shopcolor);
        $("#myModal").modal('show');
    }
    $(function(){
        $(".closes").on("click",function(){
            var id=$("[name='tableId']").val();
            $("#zstable").bootstrapTable("uncheck",id);//取消选中
            $("#myModal").modal('hide');
        })
    })
    function  cha(){//查询
        var opts = $("#mytable").bootstrapTable("getOptions") ;
        var seats=$("[name='seats']").val();
        var limit = opts.pageSize ;
        var offset = (opts.pageNumber-1) * limit;
        $.ajax({
            url:"/godowns/showGodown",
            type:"get",
            data:{"seat":seats,"stateId":2,'limit':limit,'offset':offset},
            success:function(data){
                $("#mytable").bootstrapTable("load",data);
            }
        })
    }
    $(function(){
        $("#mytable").bootstrapTable({
            url:"/godowns/showGodown",
            height:500,
            pageSize:10,
            pageNumber:1,
            pageList:[5,10],
            //启用分页，但是默认情况下，是客户端分页的
            pagination:true,
            sidePagination:'server',
            queryParams:function(params){
                var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                    limit: params.limit,  //页面大小
                    offset: params.offset, //页码
                    seat:$("[name='seat']").val(),
                    stateId:2,
                };
                return temp;
            },
            locale:'zh-CN',//中文支持,
            toolbar:'#top',
            columns:[
                {field:"seat",title:"单号",align:"center"},
                {field:"audit.auditTime",title:"审核日期",align:"center"},
                {field:"audit.price",title:"实付金额",align:"center"},
                {field:"audit.presetPrice",title:"应付金额",align:"center"},
                {field:"audit.sums",title:"进货总数量",align:"center"},
                {field:"audit.verifier",title:"审核人",align:"center"},
                {field:"admin.aname",title:"经办人",align:"center"},
                {
                    title:"操作备注",
                    align:"center",
                    formatter:function(value,row,index){
                        return " <button class=\"btn btn-danger\" onclick=\"show('"+index+"')\" > <span class=\"glyphicon glyphicon-plus\"></span>&nbsp;&nbsp;审核</button>&nbsp;&nbsp;&nbsp;"
                    }
                },
            ]
        });
    })
    function sk() {
        $("#mytable").bootstrapTable({
            url:"/godowns/showGodown",
            height:500,
            pageSize:10,
            pageNumber:1,
            pageList:[5,10],
            //启用分页，但是默认情况下，是客户端分页的
            pagination:true,
            sidePagination:'server',
            queryParams:function(params){
                var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                    limit: params.limit,  //页面大小
                    offset: params.offset, //页码
                    seat:null,
                    stateId:2,
                };
                return temp;
            },
            locale:'zh-CN',//中文支持,
            toolbar:'#top',
            columns:[
                {field:"seat",title:"单号",align:"center"},
                {field:"audit.auditTime",title:"审核日期",align:"center"},
                {field:"audit.price",title:"实付金额",align:"center"},
                {field:"audit.presetPrice",title:"应付金额",align:"center"},
                {field:"audit.sums",title:"进货总数量",align:"center"},
                {field:"audit.verifier",title:"审核人",align:"center"},
                {field:"admin.aname",title:"经办人",align:"center"},
                {
                    title:"操作备注",
                    align:"center",
                    formatter:function(value,row,index){
                        return " <button class=\"btn btn-danger\" onclick=\"show('"+index+"')\" > <span class=\"glyphicon glyphicon-plus\"></span>&nbsp;&nbsp;审核</button>&nbsp;&nbsp;&nbsp;"
                    }
                },
            ]
        });
    }
</script>
</body>
</html>
